package com.dreamder.util;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.Serializable;
import java.io.StreamCorruptedException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

public class TesteService implements Runnable {

	final static String URL_SERVER = "http://192.168.1.104:8080/dreamder-web/logarUsuario";
	private String mensagem = "";

	public String getMensagem() {
		return mensagem;
	}

	public void setMensagem(String mensagem) {
		this.mensagem = mensagem;
	}

	@Override
	public void run() {

		synchronized (this) {

			try {
				URL url = new URL(URL_SERVER);

				HttpURLConnection http = (HttpURLConnection) url
						.openConnection();
				http.setRequestMethod("POST");
				http.addRequestProperty("content-type", "application/binary");
				http.setDoInput(true);
				// http.setDoOutput(true);
				http.setConnectTimeout(20000);

				http.connect();

				// ObjectOutputStream oos = new ObjectOutputStream(
				// http.getOutputStream());
				// Livro l = new Livro();
				// oos.writeObject(l);

				ObjectInputStream ois = new ObjectInputStream(
						http.getInputStream());
				Serializable msg = (Serializable) ois.readObject();
				mensagem = (String) msg;

				notifyAll();

			} catch (MalformedURLException e) {
				// TODO Auto-generated catch block
				mensagem = null;
			} catch (StreamCorruptedException e) {
				// TODO Auto-generated catch block
				mensagem = null;
			} catch (IOException e) {
				// TODO Auto-generated catch block
				mensagem = null;
			} catch (ClassNotFoundException e) {
				// TODO Auto-generated catch block
				mensagem = null;
			} finally {
				notifyAll();
			}

		}

	}
}
